package com.competition.jingdong;
//耗材
//耗材名称,耗材类型,长,宽,高
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

//耗材
//耗材名称,耗材类型,长,宽,高
public class ConsumeCsvProcess{
    public void processing(Path path, String charset, List listBox) {
        listBox.clear();
        try {
            BufferedReader br = Files.newBufferedReader(path, Charset.forName(charset));
            String s = br.readLine();//处理标题栏
            s=br.readLine();
            while(s!=null)
            {
                String[] sArray = s.split(",");
                String consumeName = sArray[0];
                String consumeType = sArray[1];
                Integer length = Integer.valueOf(sArray[2]);
                Integer weight = Integer.valueOf(sArray[3]);
                Integer high = Integer.valueOf(sArray[4]);
                if(consumeType.equals("袋"))
                {
                    int z = (int)Math.ceil((length+weight - Math.ceil(Math.sqrt(Math.pow((length-weight),2)+length*weight)))/3.0);
                    int x = length-z;
                    int y = weight-z;
                    Consume consume = new Consume(consumeName,consumeType,x,y,z);
                    listBox.add(consume);
                }
                else
                {
                    Consume consume = new Consume(consumeName,consumeType,length,weight,high);
                    listBox.add(consume);
                }
                s=br.readLine();
            }
            Collections.sort(listBox);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
